/*
The surface-physics project: http://code.google.com/p/surface-physics/
Adds real world physics based on the Bullet physics engine, to bases in the Orbiter space
flight simulation software.

Written by Abhijit Nandy
License : Apache License 2.0

Bump_SimpleRigidBody.h
BulletBase non-attachment, mesh based object management directly from within Bump
This class is a Component based object, specifically for modeling a simple rigid body
It allows bodies that can be approximated with a single geometry which are :
1. Sphere (parameters : radius, position, orientation)
2. Cylinder (parameters : radius, length, position, orientation)
3. Box (parameters : radius, length, position, orientation)
4. Cone
5. Capsule




It adds animations and uses Euler angles to transform the object properly


TODO : This class should read the options section of this object from the physics file
 The options section will have the mesh file to use and collision shape details

*/


#pragma once


#include "../Terrain/Bump_TerrainPatchOru.h"
#include "../BulletBase/Bump_MshCollisionShape.h"


/**
 * The Bump_SimpleRigidBody class to create and load simple meshes and manage them
 */
class Bump_SimpleRigidBody : Bump_BaseObject
{
	static Registrar registrar;

	//Physics stuff
	btRigidBody *rbSimple;
	btScalar mass;

	//Position in Bullet world
	double x, y, z;
	float rx, ry, rz;
	double angle;



	//Current position wrt base, required for ground patch
	VECTOR3 rposCurrent, gposCurrent;
	double lng, lat, rad;


	//Animation stuff
	MGROUP_TRANSLATE *mgtTY, *mgtTZ; //mgtTX is static and declared in function(must be as its first)
	MGROUP_ROTATE *mgrRX, *mgrRY, *mgrRZ;
	UINT animTX, animTY, animTZ, animRX, animRY, animRZ;

	ANIMATIONCOMPONENT_HANDLE parent;
	UINT mshIndex;
	static const int GROUP_INDEX = 0;

	//Supporting terrain
	Bump_TerrainPatch *ground;

	//Test collmesh
	Bump_MshCollisionShape testCollMsh;



public:

	static Bump_BaseObject * create() { return new Bump_SimpleRigidBody; }

	static int count;

	Bump_SimpleRigidBody();
	virtual ~Bump_SimpleRigidBody();

	//Main control functions which are overidden from parent as they are called from Bump_BulletBase
	int		clbkSetClassCaps(void);
	int		clbkPostStep(double SimT, double SimDT, double MJD);
	int		clbkLoadState(FILEHANDLE file);
	int		clbkSaveState(FILEHANDLE file);


	//Utility stuff
	int		createOrbiterPrimitives();
	int 	destroyOrbiterPrimitives();

	int		createBulletRigidBody();
	int		destroyBulletRigidBody();

	int		processCommand();


};
